#include "MultiValueItem.h"



MultiValueItem::MultiValueItem(AbstractItem* parent)
    : AbstractItem(parent)
{
}


int MultiValueItem::fieldCount() const
{
    return (AbstractItem::DataType_LAST - AbstractItem::DataType_FIRST + d->values.count());
}


QString MultiValueItem::fieldName(const int &field) const
{
    if (field < UserField) return AbstractItem::fieldName(field);

    int index = field - UserField;
    if (index < 0 || index >= d->values.count()) return QString::null;

    return d->values.keys().at(index);
}


int MultiValueItem::field(const QString& name) const
{
    if (!d->values.contains(name)) return AbstractItem::field(name);

    return d->values.keys().indexOf(name);
}


void MultiValueItem::setField(const QString& name, const QVariant& data)
{
    d->values[name] = data;
}



void MultiValueItem::setCustomData(const int &field, const QVariant &data)
{
    int index = field - UserField;
    if (index < 0 || index >= d->values.count()) return;

    QString name = d->values.keys().at(index);
    d->values[name] = data;
}


QVariant MultiValueItem::customData(const int &field, int role) const
{
    Q_UNUSED(role);

    int index = field - UserField;
    if (index < 0 || index >= d->values.count()) return QVariant();

    QString name = d->values.keys().at(index);
    return d->values.value(name, QVariant());
}
